import React, { PureComponent } from 'react';
import { connect } from 'dva';
import NewsList from '../../components/News/NewList';

// @connect(({data,ok}) => ({
//     data,
//     ok,
// }))
@connect(state => ({
  news: state.news,
}))
// @connect(({news}) => ({
//     data:news.data,
//     ok:news.ok,
// }))
export default class News extends PureComponent {
  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'news/fetch',
      payload: {
        page: 1,
      },
    });
  }

  handleDetail(id) {
    alert(id);
  }

  render() {
    const { news } = this.props;
    console.log('news data:', this.props);
    // const ok = news.ok;
    const pages = news.data.meta;
    const list = news.data.object_list;
    console.log('pages:', pages);
    console.log('news:', list);
    return (
      <div>
        <h3>News List.</h3>
        <hr />
        <NewsList news={list} pages={pages} onDetail={this.handleDetail} />
      </div>
    );
  }
}
